/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coms.interceptors;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import java.util.Map;

/**
 *
 * @author Atul
 */
public class UserAwareInterceptor implements Interceptor {
    
    public UserAwareInterceptor() {
    }
    
    public void destroy() {
        System.out.println("UserAware Desotry");
    }
    
    public void init() {
        System.out.println("UserAware Init");
    }
    
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        Action action  = (Action) actionInvocation.getAction();
        Map<String, Object> session = actionInvocation.getInvocationContext().getSession();
        String result="error";
        if(action instanceof UserAwareInterceptor)
        {
            if(session.get("user")==null)
            {
                result = "error";
            }else{
                result= actionInvocation.invoke();
            }
        }
        return result;
    }
}
